package com.anyou.mall.fin.controller;

import java.util.ArrayList;
import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.anyou.mall.fin.param.DisableParam;
import com.anyou.mall.fin.vo.AllBondVo;
import com.anyou.mall.fin.vo.BondVo;
import com.anyou.mall.platform.vo.BondVO;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.anyou.common.annotation.Log;
import com.anyou.common.core.controller.BaseController;
import com.anyou.common.core.domain.ApiResult;
import com.anyou.common.enums.BusinessType;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import com.anyou.mall.fin.domain.Bond;
import com.anyou.mall.fin.service.IBondService;
import com.anyou.common.utils.poi.ExcelUtil;
import com.anyou.common.core.page.TableDataInfo;

/**
 * 保证金管理Controller
 *
 * @author gaochaohao
 * @date 2022-04-19
 */
@Api(tags = "保证金管理")
@RestController
@RequestMapping("/fin/bond")
public class BondController extends BaseController
{
    @Autowired
    private IBondService bondService;

//    /**
//     * 查询保证金管理列表
//     */
//    @ApiOperation("查询保证金管理列表")
//    @PreAuthorize("@ss.hasPermi('fin:bond:list')")
//    @GetMapping("/list")
//    public TableDataInfo<List<Bond>> list(Bond bond)
//    {
//        startPage();
//        List<Bond> list = bondService.selectBondList(bond);
//        return getDataTable(list);
//    }
    /**
     * 查询保证金管理列表
     */
    @ApiOperation("新保证金列表")
    @PreAuthorize("@ss.hasPermi('fin:bond:driverlist')")
    @GetMapping("/driverlist")
    public TableDataInfo<List<Bond>> list(Bond bond)
    {
        List<Bond> list =new ArrayList<>();
        //0合伙人，1维修厂，2司机
        if(bond.getBondType()==0){
            //查询合伙人列表
            startPage();
            list = bondService.selectPartnerBondList(bond);
        }
        if(bond.getBondType()==2){
            //查询司机列表
            startPage();
            list = bondService.selectDriverBondList(bond);
        }

        return getDataTable(list);
    }

    /**
     * 导出保证金管理列表
     */
    @ApiOperation("导出保证金管理列表")
    @PreAuthorize("@ss.hasPermi('fin:bond:export')")
    @Log(title = "保证金管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Bond bond)
    {
        List<Bond> list = bondService.selectBondList(bond);
        ExcelUtil<Bond> util = new ExcelUtil<Bond>(Bond.class);
        util.exportExcel(response, list, "保证金管理数据");
    }

    /**
     * 获取保证金管理详细信息
     */
    @ApiOperation("获取保证金管理详细信息")
    @PreAuthorize("@ss.hasPermi('fin:bond:query')")
    @GetMapping(value = "/{bondId}")
    public ApiResult<Bond> getInfo(@PathVariable("bondId") Long bondId)
    {
        return ApiResult.success(bondService.selectBondByBondId(bondId));
    }

    /**
     * 新增保证金管理
     */
    @ApiOperation("新增保证金管理")
    @PreAuthorize("@ss.hasPermi('fin:bond:add')")
    @Log(title = "保证金管理", businessType = BusinessType.INSERT)
    @PostMapping
    public ApiResult add(@RequestBody Bond bond)
    {
        return ApiResult.success(bondService.insertBond(bond));
    }

    /**
     * 修改保证金管理
     */
    @ApiOperation("修改保证金管理")
    @PreAuthorize("@ss.hasPermi('fin:bond:edit')")
    @Log(title = "保证金管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public ApiResult edit(@RequestBody Bond bond)
    {
        return ApiResult.success(bondService.updateBond(bond));
    }

    /**
     * 删除保证金管理
     */
    @ApiOperation("删除保证金管理")
    @PreAuthorize("@ss.hasPermi('fin:bond:remove')")
    @Log(title = "保证金管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{bondIds}")
    public ApiResult remove(@PathVariable Long[] bondIds)
    {
        return ApiResult.success(bondService.deleteBondByBondIds(bondIds));
    }

    /**
     * 启用禁用接口
     */
    @ApiOperation("启用禁用接口")
    @PreAuthorize("@ss.hasPermi('fin:bond:disable')")
    @PostMapping("/disable")
    public ApiResult disable(@RequestBody DisableParam disableParam) {
        return bondService.disable(disableParam);
    }

    /**
     * 获取保证金总额
     */
    @ApiOperation("获取保证金总额")
    @PreAuthorize("@ss.hasPermi('fin:bond:allBond')")
    @GetMapping("/allBond")
    public ApiResult<AllBondVo> allBond() {
        return bondService.allBond();
    }
}
